<?php
include         '../data/toolmaking_dal.php';
include_once    '../entity/toolmaking_entity.php';

class ToolmakingMng
{
    function update($toolmakingEntity)
    {
        $toolmakingDAL = new ToolmakingDAL();
        return $toolmakingDAL->update($toolmakingEntity->id,
                                      $toolmakingEntity->rfqID,
                                      $toolmakingEntity->quote,
                                      $toolmakingEntity->attached,
                                      $toolmakingEntity->advise,
                                      $toolmakingEntity->cavities,
                                      $toolmakingEntity->steel,
                                      $toolmakingEntity->prefened,
                                      $toolmakingEntity->other,
                                      $toolmakingEntity->information,
                                      $toolmakingEntity->inTime,
                                      $toolmakingEntity->inUser);
    }

    function get($id)
    {
        $where = "id = " . $id;
        $toolmakingDAL = new ToolmakingDAL();
        if ($result = $toolmakingDAL->get($where)) {
            $row = $result->fetch_assoc();
            $toolmakingEntity = new ToolMaking_Entity();
            foreach ($row as $key => $value) {
                $toolmakingEntity->$key = $value;
            }
            return $toolmakingEntity;
        } else {
            return false;
        }
    }

    function getAll($start, $pageSize, $sortField, $sortDirection)
    {
        $orderBy = "ORDER BY " . $sortField . " " . $sortDirection . " LIMIT " . $start . ", " . ($pageSize * ($start + 1));
        $toolmakingDAL = new ToolmakingDAL();
        if ($result = $toolmakingDAL->getAll($orderBy)) {
            while ($row = $result->fetch_array()) {
                $toolmakingList[] = $row;
            }
            return $toolmakingList;
        } else {
            return false;
        }
    }

    function delete($id)
    {
        $toolmakingDAL = new ToolmakingDAL();
        return $toolmakingDAL->delete($id);
    }
}
?>
